﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace TierApplication
{
	/// <summary>
	/// 类T_CART。
	/// </summary>
	[Serializable]
	public partial class T_CART
	{
		public T_CART()
		{}
		#region Model
		private string _cartid;
		private string _accountid;
		private decimal? _unitprice;
		private decimal? _quantity;
		private decimal? _fee;
		private decimal? _discount;
		private string _productid;
		private decimal? _point;
		/// <summary>
		/// 序列号
		/// </summary>
		public string CARTID
		{
			set{ _cartid=value;}
			get{return _cartid;}
		}
		/// <summary>
		/// 用户账号
		/// </summary>
		public string ACCOUNTID
		{
			set{ _accountid=value;}
			get{return _accountid;}
		}
		/// <summary>
		/// 商品单价
		/// </summary>
		public decimal? UNITPRICE
		{
			set{ _unitprice=value;}
			get{return _unitprice;}
		}
		/// <summary>
		/// 商品数量
		/// </summary>
		public decimal? QUANTITY
		{
			set{ _quantity=value;}
			get{return _quantity;}
		}
		/// <summary>
		/// 商品金额
		/// </summary>
		public decimal? FEE
		{
			set{ _fee=value;}
			get{return _fee;}
		}
		/// <summary>
		/// 折扣
		/// </summary>
		public decimal? DISCOUNT
		{
			set{ _discount=value;}
			get{return _discount;}
		}
		/// <summary>
		/// 商品编号(T_Product)
		/// </summary>
		public string PRODUCTID
		{
			set{ _productid=value;}
			get{return _productid;}
		}
		/// <summary>
		/// 积分
		/// </summary>
		public decimal? POINT
		{
			set{ _point=value;}
			get{return _point;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public T_CART(string CARTID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select CARTID,ACCOUNTID,UNITPRICE,QUANTITY,FEE,DISCOUNT,PRODUCTID,POINT ");
			strSql.Append(" FROM T_CART ");
			strSql.Append(" where CARTID=:CARTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":CARTID", OracleType.VarChar,50)};
			parameters[0].Value = CARTID;

			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["CARTID"]!=null && ds.Tables[0].Rows[0]["CARTID"].ToString()!="")
				{
					this.CARTID=ds.Tables[0].Rows[0]["CARTID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ACCOUNTID"]!=null && ds.Tables[0].Rows[0]["ACCOUNTID"].ToString()!="")
				{
					this.ACCOUNTID=ds.Tables[0].Rows[0]["ACCOUNTID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UNITPRICE"]!=null && ds.Tables[0].Rows[0]["UNITPRICE"].ToString()!="")
				{
					this.UNITPRICE=decimal.Parse(ds.Tables[0].Rows[0]["UNITPRICE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["QUANTITY"]!=null && ds.Tables[0].Rows[0]["QUANTITY"].ToString()!="")
				{
					this.QUANTITY=decimal.Parse(ds.Tables[0].Rows[0]["QUANTITY"].ToString());
				}
				if(ds.Tables[0].Rows[0]["FEE"]!=null && ds.Tables[0].Rows[0]["FEE"].ToString()!="")
				{
					this.FEE=decimal.Parse(ds.Tables[0].Rows[0]["FEE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["DISCOUNT"]!=null && ds.Tables[0].Rows[0]["DISCOUNT"].ToString()!="")
				{
					this.DISCOUNT=decimal.Parse(ds.Tables[0].Rows[0]["DISCOUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PRODUCTID"]!=null && ds.Tables[0].Rows[0]["PRODUCTID"].ToString()!="")
				{
					this.PRODUCTID=ds.Tables[0].Rows[0]["PRODUCTID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["POINT"]!=null && ds.Tables[0].Rows[0]["POINT"].ToString()!="")
				{
					this.POINT=decimal.Parse(ds.Tables[0].Rows[0]["POINT"].ToString());
				}
			}
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string CARTID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_CART");
			strSql.Append(" where CARTID=:CARTID ");

			OracleParameter[] parameters = {
					new OracleParameter(":CARTID", OracleType.VarChar,50)};
			parameters[0].Value = CARTID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_CART (");
			strSql.Append("CARTID,ACCOUNTID,UNITPRICE,QUANTITY,FEE,DISCOUNT,PRODUCTID,POINT)");
			strSql.Append(" values (");
			strSql.Append(":CARTID,:ACCOUNTID,:UNITPRICE,:QUANTITY,:FEE,:DISCOUNT,:PRODUCTID,:POINT)");
			OracleParameter[] parameters = {
					new OracleParameter(":CARTID", OracleType.VarChar,10),
					new OracleParameter(":ACCOUNTID", OracleType.VarChar,20),
					new OracleParameter(":UNITPRICE", OracleType.Number,12),
					new OracleParameter(":QUANTITY", OracleType.Number,12),
					new OracleParameter(":FEE", OracleType.Number,12),
					new OracleParameter(":DISCOUNT", OracleType.Number,12),
					new OracleParameter(":PRODUCTID", OracleType.VarChar,10),
					new OracleParameter(":POINT", OracleType.Number,12)};
			parameters[0].Value = CARTID;
			parameters[1].Value = ACCOUNTID;
			parameters[2].Value = UNITPRICE;
			parameters[3].Value = QUANTITY;
			parameters[4].Value = FEE;
			parameters[5].Value = DISCOUNT;
			parameters[6].Value = PRODUCTID;
			parameters[7].Value = POINT;

			DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_CART set ");
			strSql.Append("ACCOUNTID=:ACCOUNTID,");
			strSql.Append("UNITPRICE=:UNITPRICE,");
			strSql.Append("QUANTITY=:QUANTITY,");
			strSql.Append("FEE=:FEE,");
			strSql.Append("DISCOUNT=:DISCOUNT,");
			strSql.Append("PRODUCTID=:PRODUCTID,");
			strSql.Append("POINT=:POINT");
			strSql.Append(" where CARTID=:CARTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ACCOUNTID", OracleType.VarChar,20),
					new OracleParameter(":UNITPRICE", OracleType.Number,12),
					new OracleParameter(":QUANTITY", OracleType.Number,12),
					new OracleParameter(":FEE", OracleType.Number,12),
					new OracleParameter(":DISCOUNT", OracleType.Number,12),
					new OracleParameter(":PRODUCTID", OracleType.VarChar,10),
					new OracleParameter(":POINT", OracleType.Number,12),
					new OracleParameter(":CARTID", OracleType.VarChar,10)};
			parameters[0].Value = ACCOUNTID;
			parameters[1].Value = UNITPRICE;
			parameters[2].Value = QUANTITY;
			parameters[3].Value = FEE;
			parameters[4].Value = DISCOUNT;
			parameters[5].Value = PRODUCTID;
			parameters[6].Value = POINT;
			parameters[7].Value = CARTID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string CARTID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_CART ");
			strSql.Append(" where CARTID=:CARTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":CARTID", OracleType.VarChar,50)};
			parameters[0].Value = CARTID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(string CARTID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select CARTID,ACCOUNTID,UNITPRICE,QUANTITY,FEE,DISCOUNT,PRODUCTID,POINT ");
			strSql.Append(" FROM T_CART ");
			strSql.Append(" where CARTID=:CARTID ");
			OracleParameter[] parameters = {
					new OracleParameter(":CARTID", OracleType.VarChar,50)};
			parameters[0].Value = CARTID;

			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["CARTID"]!=null && ds.Tables[0].Rows[0]["CARTID"].ToString()!="")
				{
					this.CARTID=ds.Tables[0].Rows[0]["CARTID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ACCOUNTID"]!=null && ds.Tables[0].Rows[0]["ACCOUNTID"].ToString()!="")
				{
					this.ACCOUNTID=ds.Tables[0].Rows[0]["ACCOUNTID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UNITPRICE"]!=null && ds.Tables[0].Rows[0]["UNITPRICE"].ToString()!="")
				{
					this.UNITPRICE=decimal.Parse(ds.Tables[0].Rows[0]["UNITPRICE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["QUANTITY"]!=null && ds.Tables[0].Rows[0]["QUANTITY"].ToString()!="")
				{
					this.QUANTITY=decimal.Parse(ds.Tables[0].Rows[0]["QUANTITY"].ToString());
				}
				if(ds.Tables[0].Rows[0]["FEE"]!=null && ds.Tables[0].Rows[0]["FEE"].ToString()!="")
				{
					this.FEE=decimal.Parse(ds.Tables[0].Rows[0]["FEE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["DISCOUNT"]!=null && ds.Tables[0].Rows[0]["DISCOUNT"].ToString()!="")
				{
					this.DISCOUNT=decimal.Parse(ds.Tables[0].Rows[0]["DISCOUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PRODUCTID"]!=null && ds.Tables[0].Rows[0]["PRODUCTID"].ToString()!="")
				{
					this.PRODUCTID=ds.Tables[0].Rows[0]["PRODUCTID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["POINT"]!=null && ds.Tables[0].Rows[0]["POINT"].ToString()!="")
				{
					this.POINT=decimal.Parse(ds.Tables[0].Rows[0]["POINT"].ToString());
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM T_CART ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

